package com.glodon.paas.monitor.server.biz.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glodon.paas.monitor.server.biz.domain.MonitorPluginEntity;
import com.glodon.paas.monitor.server.biz.mapper.MonitorPluginMapper;
import com.glodon.paas.monitor.server.biz.service.MonitorPluginService;
import com.glodon.paas.monitor.server.exception.MonitorException;

@Service("monitorPluginService")
public class MonitorPluginServiceImpl implements MonitorPluginService {

	@Autowired
	private MonitorPluginMapper	monitorPluginMapper;

	@Override
	public int deleteByPrimaryKey(Long id) {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"deleteByPrimaryKey plugin id is null!");
		}
		return monitorPluginMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(MonitorPluginEntity record) {
		if (null == record || StringUtils.isBlank(record.getPluginName())) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "insert plugin record is null!");
		}
		return monitorPluginMapper.insert(record);
	}

	@Override
	public int insertSelective(MonitorPluginEntity record) {
		if (null == record || StringUtils.isBlank(record.getPluginName())) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"insertSelective plugin record is null!");
		}
		return monitorPluginMapper.insertSelective(record);
	}

	@Override
	public MonitorPluginEntity selectByPrimaryKey(Long id) {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByPrimaryKey plugin id is null!");
		}
		return monitorPluginMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(MonitorPluginEntity record) {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKeySelective plugin record is null!");
		}
		return monitorPluginMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(MonitorPluginEntity record) {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKey plugin record is null!");
		}
		return monitorPluginMapper.updateByPrimaryKey(record);
	}

	public List<MonitorPluginEntity> listAllPlugin() {

		return monitorPluginMapper.listAllPlugin();
	}

}
